package com.cm.demo1.mapper;

import com.cm.demo1.entity.Drugs;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 药物Mapper接口
 */
@Mapper
public interface DrugsMapper {

    /**
     * 新增药物
     * @param drugs 药物信息
     * @return 影响行数
     */
    @Insert("INSERT INTO drugs(name, category, manufacturer, price, description, stock) VALUES(#{name}, #{category}, #{manufacturer}, #{price}, #{description}, #{stock})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Drugs drugs);

    /**
     * 删除药物
     * @param id 药物ID
     * @return 影响行数
     */
    @Delete("DELETE FROM drugs WHERE id = #{id}")
    int deleteById(Integer id);

    /**
     * 更新药物信息
     * @param drugs 药物信息
     * @return 影响行数
     */
    @Update("UPDATE drugs SET name = #{name}, category = #{category}, manufacturer = #{manufacturer}, price = #{price}, description = #{description}, stock = #{stock} WHERE id = #{id}")
    int updateById(Drugs drugs);

    /**
     * 根据ID查询药物
     * @param id 药物ID
     * @return 药物信息
     */
    @Select("SELECT * FROM drugs WHERE id = #{id}")
    Drugs selectById(Integer id);

    /**
     * 查询所有药物
     * @return 药物列表
     */
    @Select("SELECT * FROM drugs")
    List<Drugs> selectAll();
}